package com.parse.ast;

import com.lex.Token;
import com.parse.Scope;
import com.parse.SymbolTable;

import java.util.ArrayList;
import java.util.List;

public class ASTNode {

    private ASTNode parent;
    private ASTNodeType type;
    private String text;
    private List<ASTNode> children = new ArrayList<>();
    private SymbolTable symbolTable;
    private Scope scope;
    private int startLine;
    private int endLine;
    private int startColumn;
    private int endColumn;

    public ASTNode(ASTNodeType type) {
        this.type = type;
        this.text = null;
    }
    public ASTNode(ASTNodeType type,Token token) {
        this.type = type;
        this.text = token.getValue();
        this.startLine = token.getStartLine();
        this.endLine = token.getEndLine();
        this.startColumn = token.getStartColumn();
        this.endColumn = token.getEndColumn();
    }

    public ASTNode(ASTNodeType type,Token token,ASTNode parent) {
        this.type = type;
        this.text = token.getValue();
        this.startLine = token.getStartLine();
        this.endLine = token.getEndLine();
        this.startColumn = token.getStartColumn();
        this.endColumn = token.getEndColumn();
        this.parent = parent;
    }

    public void addChild(ASTNode child) {
        children.add(child);
        child.setParent(this);
    }

    public ASTNodeType getType() {
        return type;
    }

    public String getText() {
        return text;
    }

    public List<ASTNode> getChildren() {
        return children;
    }

    public SymbolTable getSymbolTable() {
        return symbolTable;
    }

    public void setSymbolTable(SymbolTable symbolTable) {
        this.symbolTable = symbolTable;
    }

    public Scope getScope() {
        return scope;
    }

    public void setScope(Scope scope) {
        this.scope = scope;
    }

    public int getStartLine() {
        return startLine;
    }

    public int getEndLine() {
        return endLine;
    }

    public int getStartColumn() {
        return startColumn;
    }

    public int getEndColumn() {
        return endColumn;
    }

    public ASTNode getParent() {
        return parent;
    }

    public void setParent(ASTNode parent) {
        this.parent = parent;
    }

    // Other methods, such as toString(), accept(), etc.
}


